function [Vulner_node] = gretna_vulnerability(A)

%==========================================================================
% This function is used to calculate nodal vulnerability for a binary graph
% or network G.
% 
%
% Syntax: function [Vulner_node] = gretna_vulnerability(A)
% 
% Input:
%     A:            
%                   The adjacency matrix of G (N*N, symmetric).
%
% Output:
%     Vulner_node:  
%                   The vulnerability of each node in G.
%
% Yong HE,     NKLCNL, BNU, BeiJing, 2011/03/12
% Jinhui WANG, NKLCNL, BNU, BeiJing, 2011/10/23, Jinhui.Wang.1982@gmail.com
%==========================================================================

A = A - diag(diag(A));
A = abs(A);
N = length(A);

[averlp, ~] = gretna_node_shortestpathlength(A);
Lp_raw = averlp;

Lp_removenode = zeros(N,1);

for i =1:N
    A_removenode = A;
    A_removenode(i,:) = [];
    A_removenode(:,i) = [];
    [averlp, ~] = gretna_node_shortestpathlength(A_removenode);
    Lp_removenode(i) = averlp;
end

Vulner_node = 100*(Lp_removenode - Lp_raw)/Lp_raw;

return